/*
 * MarkovChainHistoryComponent.java
 *
 * Created on 8 de Julho de 2011, 16:44
 */

package intopo.demonstrator.partnerselection.gui;

/**
 *
 * @author  pedro
 */
public class MarkovChainHistoryComponent extends javax.swing.JPanel
{
	private TableTimeAcceptableCombination tableTimeAcceptableCombination;
	private TableSelectedAcceptableCombinations tableSelectedAcceptableCombinations;
	
	/** Creates new form BeanForm */
	public MarkovChainHistoryComponent ()
	{
		tableTimeAcceptableCombination = new TableTimeAcceptableCombination ();
		tableSelectedAcceptableCombinations = new TableSelectedAcceptableCombinations ();
		initComponents ();
	}
	
//	public void setMarkovChain (MarkovChain mc)
//	{
//		this.markovChain = mc;
//		newState ();
//	}

	void parametersChanged ()
	{
		this.timeTextField.setText (Integer.toString (0));
		this.tableTimeAcceptableCombination.fireTableDataChanged ();
		this.tableSelectedAcceptableCombinations.fireTableDataChanged ();
		repaint ();
	}
	void newTransition ()
	{
		this.timeTextField.setText (Long.toString (DataModel.markovChain.getTime ()));
		this.tableTimeAcceptableCombination.fireTableDataChanged ();
		this.tableSelectedAcceptableCombinations.fireTableDataChanged ();
	}
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
   // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
   private void initComponents() {
      javax.swing.JLabel jLabel1;
      javax.swing.JPanel jPanel1;
      javax.swing.JScrollPane jScrollPane1;
      javax.swing.JTable jTable1;

      jPanel1 = new javax.swing.JPanel();
      jScrollPane1 = new javax.swing.JScrollPane();
      jTable1 = new javax.swing.JTable();
      jPanel2 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      timeTextField = new javax.swing.JTextField();
      jPanel3 = new javax.swing.JPanel();
      jScrollPane2 = new javax.swing.JScrollPane();
      jTable2 = new javax.swing.JTable();

      setLayout(new java.awt.BorderLayout());

      jPanel1.setLayout(new java.awt.BorderLayout());

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Time to acceptable combination"));
      jScrollPane1.setPreferredSize(new java.awt.Dimension(220, 203));
      jTable1.setModel(tableTimeAcceptableCombination);
      jScrollPane1.setViewportView(jTable1);

      jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

      add(jPanel1, java.awt.BorderLayout.CENTER);

      jPanel2.setLayout(new java.awt.GridBagLayout());

      jLabel1.setText("Time: ");
      jPanel2.add(jLabel1, new java.awt.GridBagConstraints());

      timeTextField.setColumns(10);
      timeTextField.setEditable(false);
      jPanel2.add(timeTextField, new java.awt.GridBagConstraints());

      add(jPanel2, java.awt.BorderLayout.NORTH);

      jPanel3.setLayout(new java.awt.BorderLayout());

      jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Selected Acceptable Combinations"));
      jScrollPane2.setPreferredSize(new java.awt.Dimension(220, 203));
      jTable2.setModel(tableSelectedAcceptableCombinations);
      jScrollPane2.setViewportView(jTable2);

      jPanel3.add(jScrollPane2, java.awt.BorderLayout.CENTER);

      add(jPanel3, java.awt.BorderLayout.SOUTH);

   }// </editor-fold>//GEN-END:initComponents
	
	
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JPanel jPanel2;
   private javax.swing.JPanel jPanel3;
   private javax.swing.JScrollPane jScrollPane2;
   private javax.swing.JTable jTable2;
   private javax.swing.JTextField timeTextField;
   // End of variables declaration//GEN-END:variables
	


	
		
	class TableTimeAcceptableCombination
		extends javax.swing.table.AbstractTableModel
	{
		TableTimeAcceptableCombination ()
		{
		}
		public int getColumnCount ()
		{
			return 2;
		}
		public int getRowCount ()
		{
			return DataModel.markovChain.getAcceptableCombinationsCount ();
		}
		public Object getValueAt (int row, int column)
		{
			switch (column) {
			case 0:
				return Integer.toString (row + 1);
			case 1:
				return Long.toString (DataModel.markovChain.getTimeAcceptableCombination (row + 1));
			}
			return null;
		}
		public Class<?> getColumnClass (int column)
		{
			switch (column) {
			case 0:
				return Integer.class;
			case 1:
				return Long.class;
			}
			return null;
		}
		public String getColumnName (int column)
		{
			switch (column) {
			case 0:
				return "#";
			case 1:
				return "time";
			}
			return null;
		}
	}
	class TableSelectedAcceptableCombinations
		extends javax.swing.table.AbstractTableModel
	{
		public int getColumnCount ()
		{
			return 2;
		}
		public int getRowCount ()
		{
			if (DataModel.markovChain.getParameters ().getPoolSize () == DataModel.markovChain.getAcceptableCombinationsCount ())
				return DataModel.markovChain.getParameters ().getPoolSize () - 1;
			else
				return DataModel.markovChain.getAcceptableCombinationsCount ();
		}
		public Object getValueAt (int row, int column)
		{
			switch (column) {
			case 0:
				return Integer.toString (row + 1);
			case 1:
				return Integer.toString (DataModel.markovChain.getSelectedAcceptableCombinations (row + 1));
			}
			return null;
		}
		public Class<?> getColumnClass (int column)
		{
			switch (column) {
			case 0:
			case 1:
				return Integer.class;
			}
			return null;
		}
		public String getColumnName (int column)
		{
			switch (column) {
			case 0:
				return "# combinations";
			case 1:
				return "# selected";
			}
			return null;
		}
	}
}